<template>
    <li :class="classes" @click.stop="select">
      <slot></slot>
    </li>
    <!-- <li class="ifast-dropdown-item ifast-dropdown-checked" v-for="i in 5" :key="i" @click="select">
        <span class="item-text"> {{i}}</span>
        <span class="float-right">123123123</span>
        <span class="item-right select-right">
          <Icon type="ion-ios-checkmark-empty"></Icon>
        </span>
    </li> -->
</template>

<script>
let prefixCls='ifast'

import emitter from '../../utils/emitter.js'
    import { findComponentUpward } from '../../utils/index.js';

export default {
  name: 'Opction',
  mixins:[emitter],
  props:{
    label:{
      type:[String,Number],
      required:true
    },
    value:{
      type:[String,Number]
    },
    disabled: {
        type: Boolean,
        default: false
    },
    isFocused: {
        type: Boolean,
        default: false
    },
    selected:{
      type:Boolean,
      default:false,
    }
  },
  computed:{
    classes(){
      return[
        `${prefixCls}-dropdown-item`,
        [{
          [`${prefixCls}-dropdown-checked`]:this.selected,
          [`${prefixCls}-dropdown-isFocused`]:this.isFocused,
          [`${prefixCls}-dropdown-disabled`]:this.disabled

        }]
      ]
    }
  },
  data () {
    return {
      parent:findComponentUpward(this,'iSelect'),
      multiple:false,
    }
  },

  methods: {
    select(){
      if (this.disabled) return false;
        this.dispatch('iSelect', 'on-select-selected', {
            value: this.value,
            label: this.label,
        });
        this.$emit('on-select-selected', {
            value: this.value,
            label: this.label,
        });
        // this.selected=!this.selected;
        // let v=this.value?this.value:this.label;
        // let currentValue=this.parent.currentValue;
        // let selecteds=this.parent.selecteds;
        // debugger;
        // if(this.multiple){
        //   if(selecteds.indexOf(v)!=-1){
        //     this.selected=true;
        //   }else{
        //     this.selected=false;
        //   }
        // }else{
        //   if(v===currentValue){
        //     this.selected=true
        //   }else{
        //     this.selected=false
        //   }
        // }
    }
  },
  mounted(){
    if(this.parent) this.multiple=this.parent.multiple;

  }
}
</script>

<style lang='scss' scoped>

</style>
